//
//  XMChatImageMessageTableViewCell.m
//  XMenSwift
//
//  Created by Jason on 2022/9/15.
//

#import "XMChatImageMessageTableViewCell.h"
#import <Masonry/Masonry.h>

@interface XMChatImageMessageTableViewCell()

@property (strong, nonatomic) UIImageView *pictureImageView;

@end

@implementation XMChatImageMessageTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self steupUi];
    }
    return self;
}

- (void)steupUi {
    
    UIView *bgView = [[UIView alloc] init];
    [self.contentView addSubview:bgView];
    [bgView addSubview:self.userImageView];
    
    [bgView addSubview:self.nickLabel];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView);
    }];
    
    [self.userImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView).offset(10);
        make.right.equalTo(bgView).offset(-10);
        make.width.mas_equalTo(50);
        make.height.mas_equalTo(50);

    }];
    
    [self.nickLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.userImageView.mas_top);
        make.right.equalTo(self.userImageView.mas_left).offset(-10);
        make.left.equalTo(bgView).offset(-10);
        make.height.mas_equalTo(20);

    }];
    
    UIView *imageBgView = [[UIView alloc] init];
    [bgView addSubview:imageBgView];
    [imageBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.nickLabel.mas_bottom).offset(5);
        make.right.equalTo(self.nickLabel.mas_right);
        make.width.mas_equalTo(85);
        make.height.mas_equalTo(130);
        make.bottom.equalTo(bgView).offset(-10);
    }];

    UIImageView *imageView = [[UIImageView alloc] init];
    _pictureImageView = imageView;
    imageView.contentMode = UIViewContentModeScaleAspectFill;
    imageView.layer.masksToBounds = YES;
    imageView.layer.cornerRadius = 4;
    [imageBgView addSubview:imageView];
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(imageBgView);
    }];
    
    [bgView addSubview:self.activityView];
    [self.activityView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(imageBgView.mas_left).offset(-5);
        make.centerY.equalTo(imageBgView.mas_centerY);
        make.width.mas_equalTo(20);
        make.height.mas_equalTo(20);
    }];
    
    [bgView addSubview:self.retryBtn];
    [self.retryBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(imageBgView.mas_left);
        make.centerY.equalTo(imageBgView.mas_centerY);
        make.width.mas_equalTo(40);
        make.height.mas_equalTo(40);
    }];
    
    
}

- (void)setConfig:(WZMChatMessageModel *)model {
    [super setConfig:model];
    self.pictureImageView.image = [UIImage imageNamed:@"1_t"];
}

@end
